package com.open.loan.utils;

import java.io.IOException;
import java.util.LinkedHashMap;

import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSONObject;

public class ResponseUtil {
	
	public static void toWrite(String code,String msg,Object obj,HttpServletResponse response){
        response.setCharacterEncoding("UTF-8");
        response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1
        response.setHeader("Pragma", "no-cache"); // HTTP 1.0
        response.setDateHeader("Expires", 0); // Proxies.
        response.setHeader("Access-Control-Allow-Origin", "*");
        response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
        response.setHeader("Access-Control-Max-Age", "3600");
        response.setHeader("Access-Control-Allow-Headers", "x-requested-with,Authorization");
        response.setHeader("Access-Control-Allow-Credentials","true");
		try {
			response.setContentType("text/html;charset=utf-8");
			JSONObject jsonNode = new JSONObject(new LinkedHashMap());
			jsonNode.put("code", code);
			jsonNode.put("msg", msg);
			jsonNode.put("resultInfo", obj);
			response.getWriter().write(jsonNode.toString());
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
